package com.woniu.woniuticket.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.woniuticket.entity.Seat;
import com.woniu.woniuticket.dao.SeatMapper;
import com.woniu.woniuticket.service.ISeatService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author spirit
 * @since 2020-01-02
 */
@Service
public class SeatServiceImpl extends ServiceImpl<SeatMapper, Seat> implements ISeatService {

    @Autowired
    private SeatMapper sm;

    @Override
    public String getAllSeat(Integer movieHallId, Integer showSessionId) {
        String result = sm.getAllSeat(showSessionId);
        //说明是第一次进入这个场次获取座位
        if(result == null){
            System.out.println(movieHallId+"--------"+showSessionId);
            String seat = sm.getInitialAllSeat(movieHallId);

            System.out.println(seat+"=============");
            sm.insertSeat(showSessionId,seat);
            return seat;
        }
        return result;
    }

    @Override
    public List<Seat> getInformation(Integer schoolId) {
        QueryWrapper<Seat> qw = new QueryWrapper<>();
        qw.eq("school_id",schoolId);
        List<Seat> result = sm.selectList(qw);
        System.out.println("result"+result);
        return result;
    }
}
